      1  import java.util.Scanner;

      2

      3  /**

      4     This class processes baby name records.

      5  */

      6  public class RecordReader

      7  {

      8     private double total;

      9     private double limit;

     10

     11     /**

     12        Constructs a RecordReader with a zero total.

     13     */

     14     public RecordReader(double aLimit)

     15     {

     16        total = 0;

     17        limit = aLimit;

     18     }

     19

     20     /**

     21        Reads an input record and prints the name if the current total is less

     22        than the limit.

     23        @param in the input stream

     24     */

     25     public void process(Scanner in)

     26     {

     27        String name = in.next();

     28        int count = in.nextInt();

     29        double percent = in.nextDouble();

     30

     31        if (total < limit) { System.out.print(name + " "); }

     32        total = total + percent;

     33     }

     34

     35     /**

     36        Checks whether there are more inputs to process

     37        @return true if the limit has not yet been reached

     38     */

     39     public boolean hasMore()

     40     {

     41        return total < limit;

     42     }

     43  }